//
//  CYCallRecords.m
//  CreditAddressBook
//
//  Created by Lee on 15/7/5.
//  Copyright (c) 2015年 Lee. All rights reserved.
//

#import "CYCallRecords.h"
#import "CYCallRecord.h"

@implementation CYCallRecords

- (CGFloat)viewH {
    NSInteger aa = self.callRecords.count;
    return 44 * aa;
}

- (NSArray *)callRecords {
    if (!_callRecords) {
        _callRecords = [NSArray array];
    }
    return _callRecords;
}

- (instancetype)initWithFrame:(CGRect)frame {
    self = [super initWithFrame:frame];
    if (self) {
        self.delegate = self;
        self.dataSource = self;
        self.backgroundColor = [UIColor clearColor];
    }
    return self;
}

- (void)awakeFromNib {
    [super awakeFromNib];
    self.delegate = self;
    self.dataSource = self;
    self.backgroundColor = [UIColor clearColor];
    
    [self setExtraCellLineHidden];
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return self.callRecords.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    static NSString *ID = @"cell";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:ID];
    if (!cell) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:ID];
    }
    CYCallRecord *call = self.callRecords[indexPath.row];
    cell.textLabel.text = call.newlyCallDate;
    cell.detailTextLabel.text = call.callDuration;
    UIFont *font = [UIFont systemFontOfSize:14];
    cell.textLabel.font = font;
    cell.detailTextLabel.font = font;
    cell.backgroundColor = [UIColor clearColor];
    return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
}

- (void)setExtraCellLineHidden
{
    UIView *view =[[UIView alloc]init];
    view.backgroundColor = [UIColor clearColor];
    [self setTableFooterView:view];
}

@end
